from flask_marshmallow import Schema, fields
from marshmallow import post_load

from xtoad.models import User


class UserSchema(Schema):
    class Meta:
        model = User
        # Fields to expose
        fields = ("id", "nick_name", "real_name", "pwd",
                  "sex", "email", "phone", "create_time",
                  "create_user", "update_user", "update_time")

    @post_load
    def make_user(self, data, **kwargs):
        print('post_load make_user invoked!')
        return User(**data)

